package com.mc.web.controller.lab;

import java.util.List;

import com.mc.common.core.domain.model.LoginUser;
import com.mc.common.utils.DateUtils;
import com.mc.common.utils.ServletUtils;
import com.mc.framework.web.service.TokenService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mc.common.annotation.Log;
import com.mc.common.core.controller.BaseController;
import com.mc.common.core.domain.AjaxResult;
import com.mc.common.enums.BusinessType;
import com.mc.lab.domain.LabQualification;
import com.mc.lab.service.ILabQualificationService;
import com.mc.common.utils.poi.ExcelUtil;
import com.mc.common.core.page.TableDataInfo;

/**
 * 实验室资质 Controller
 *
 * @author mc
 * @date 2021-03-18
 */
@RestController
@RequestMapping("/lab/qualification")
public class LabQualificationController extends BaseController
{
    @Autowired
    private ILabQualificationService labQualificationService;
    @Autowired
    private TokenService tokenService;


    /**
     * 查询实验室资质 列表
     */
    @PreAuthorize("@ss.hasPermi('lab:qualification:list')")
    @GetMapping("/list")
    public TableDataInfo list(LabQualification labQualification)
    {
        startPage();
        List<LabQualification> list = labQualificationService.selectLabQualificationList(labQualification);
        return getDataTable(list);
    }

    /**
     * 导出实验室资质 列表
     */
    @PreAuthorize("@ss.hasPermi('lab:qualification:export')")
    @Log(title = "实验室资质 ", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LabQualification labQualification)
    {
        List<LabQualification> list = labQualificationService.selectLabQualificationList(labQualification);
        ExcelUtil<LabQualification> util = new ExcelUtil<LabQualification>(LabQualification.class);
        return util.exportExcel(list, "qualification");
    }

    /**
     * 获取实验室资质 详细信息
     */
    @PreAuthorize("@ss.hasPermi('lab:qualification:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(labQualificationService.selectLabQualificationById(id));
    }

    /**
     * 新增实验室资质
     */
    @PreAuthorize("@ss.hasPermi('lab:qualification:add')")
    @Log(title = "实验室资质 ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LabQualification labQualification)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        labQualification.setCreateUserId(loginUser.getUsername());
        labQualification.setCreateTime(DateUtils.getNowDate());
        labQualification.setState("0");
        return toAjax(labQualificationService.insertLabQualification(labQualification));
    }

    /**
     * 修改实验室资质
     */
    @PreAuthorize("@ss.hasPermi('lab:qualification:edit')")
    @Log(title = "实验室资质 ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LabQualification labQualification)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        labQualification.setUpdateUserId(loginUser.getUsername());
        labQualification.setUpdateTime(DateUtils.getNowDate());
        labQualification.setState("0");
        return toAjax(labQualificationService.updateLabQualification(labQualification));
    }

    /**
     * 删除实验室资质
     */
    @PreAuthorize("@ss.hasPermi('lab:qualification:remove')")
    @Log(title = "实验室资质 ", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(labQualificationService.deleteLabQualificationById(id));
    }
}